package cn.ad.service;

import cn.ad.handler.SqlSessionHandler;
import cn.ad.model.Tree;
import cn.ad.entity.GeoCity;
import cn.ad.entity.GeoState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GeoCityService {
	
	@Autowired
	private SqlSessionHandler sqlSessionHandler;
	
	public List<Tree> getGeoList() {
		return sqlSessionHandler.selectList("geoCityMapper.geo:tree:list", null);
	}
	
	/**
	 * 根据城市ID查询城市名称
	 */
	public String read(int id) {
		return sqlSessionHandler.selectOne("geoCityMapper.selectCityNameById", id);
	}
	
	/**
	 * 根据省份Id查询其下所有的城市ids
	 */
	public List<Integer> getCityList(int stateId){
		
		return sqlSessionHandler.selectList("geoCityMapper.geo:citys:list:byStateId", stateId);
	}
	
	/**
	 * 查询中国下所有的省级列表
	 */
	public List<GeoState> getAllStates() {
		return sqlSessionHandler.selectList("geoCityMapper.geo:states:list:china", null);

	}

	public List<GeoCity> getAllCitys() {
		return sqlSessionHandler.selectList("geoCityMapper.select:city:list:china", null);
	}
}
